import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:panda/base/SignType.dart';
import 'package:panda/base/application.dart';
import 'package:panda/entity/order_list_entity.dart';
// import 'package:panda/goods/OrderPay.dart';
import 'package:panda/http/Api.dart';
import 'package:panda/http/HttpUtil.dart';
import 'package:panda/jiayouzhan/KefuTalk.dart';
import 'package:panda/login/Welcome.dart';
import 'package:panda/order/OrderPay.dart';
import 'package:panda/order/orderhuizhi.dart';
import 'package:panda/util/AppSaveInfoUtil.dart';
import 'package:panda/util/LoadingUtil.dart';
import 'package:panda/util/SignUtil.dart';

import '../base/Constant.dart';
import 'MyHomePage.dart';

class OrderDetailPage extends StatefulWidget {
  String order_id = "", type = "";
  OrderDetailPage({Key key, @required this.order_id, this.type})
      : super(key: key);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return OrderDetailView();
  }
}

class OrderDetailView extends State<OrderDetailPage> {
  String token = "", postage = "0";
  OrderListDataData item;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value ?? "";
      getOrderDetail();
    });
  }

  getOrderDetail() async {
    Map map = new Map();
    map['order_id'] = widget.order_id;
    map['token'] = token;
    Response<String> response = await HttpUtil().post(
        widget.type == "2"
            ? Api.BaseUrl + "/index.php/wap/UserOrder/getMsg"
            : Api.GET_ORDER_DETAIL,
        data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    // Fluttertoast.showToast(msg: response.toString());
    item = new OrderListDataData.fromJson(userMap['data']['orderMsg']);
    if (code == 1 && mounted) {
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    // TODO: implement build
    return new Scaffold(
        appBar: AppBar(
          title: Text('订单详情', style: TextStyle(fontSize: 18.0)),
          elevation: 0,
          backgroundColor: mainColor,
          actions: <Widget>[
            GestureDetector(
                onTap: () {
                  if (APPLIC.userInfoMap == null) {
                    Fluttertoast.showToast(
                        msg: "请先登录", gravity: ToastGravity.CENTER);
                    Navigator.of(context)
                        .push(new MaterialPageRoute(builder: (context) {
                      return new WelComePage();
                    }));
                    return;
                  }
                  Navigator.of(context)
                      .push(new MaterialPageRoute(builder: (context) {
                    return KeFuTalkPage(
                        url:
                            "http://kf.0731app.cn/index/index/home?visiter_id=" +
                                APPLIC.userInfoMap['user_msg']['uid']
                                    .toString() +
                                "&visiter_name=" +
                                "name" +
                                "&avatar=" +
                                APPLIC.userInfoMap['user_detail']['avatar']
                                    .toString() +
                                "&business_id=1&groupid=4&special=5");
                  }));
                },
                child: Container(
                    alignment: Alignment.center,
                    padding: EdgeInsets.fromLTRB(
                        0, ScreenUtil.getInstance().setHeight(10), 20, 0),
                    child: Column(
                      children: <Widget>[
                        Image.asset("images/lianxikefu.png",
                            width: ScreenUtil.getInstance().setHeight(40)),
                        Text('联系客服',
                            style: TextStyle(color: white, fontSize: 12))
                      ],
                    )))
          ],
        ),
        body: new SingleChildScrollView(
          child: Container(
            color: Colors.white,
            width: double.infinity,
            height: MediaQuery.of(context).size.height -
                kToolbarHeight -
                MediaQuery.of(context).padding.top,
            child: new Stack(
              children: <Widget>[
                Container(
                  // padding: EdgeInsets.all(20.0),
                  width: double.infinity,
                  decoration: new BoxDecoration(
                    color: white,
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Container(
                        padding: EdgeInsets.all(15),
                        child: Text('收件人信息', style: TextStyle(fontSize: 16)),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(15, 0, 15, 10),
                        child: new Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Image.asset('images/icon_order_location.png'),
                            Expanded(
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                                child: new Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    Text(
                                        item == null
                                            ? ""
                                            : item.consignee +
                                                "   " +
                                                item.contact_number,
                                        style: TextStyle(
                                            color: black,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(BIG_FONT_SIZE),
                                            fontWeight: FontWeight.w500)),
                                    Padding(
                                      padding: EdgeInsets.fromLTRB(0, 8, 0, 0),
                                      child: Text(
                                          item == null ? "" : item.address,
                                          style: TextStyle(
                                            color: black_99,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(SMALL_FONT_SIZE + 1),
                                          )),
                                    )
                                  ],
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
                      Container(height: 10, color: divideColor),
                      widget.type == "2"
                          ? Container(
                              padding: EdgeInsets.fromLTRB(10, 10, 0, 10),
                              child: new Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  item == null || item.img == ""
                                      ? Image.asset(
                                          'images/app_icon.png',
                                          width: ScreenUtil.getInstance()
                                              .setWidth(160),
                                          height: ScreenUtil.getInstance()
                                              .setWidth(160),
                                          fit: BoxFit.fill,
                                        )
                                      : CachedNetworkImage(
                                          imageUrl: Api.ImgBaseUrl + item.img,
                                          width: ScreenUtil.getInstance()
                                              .setWidth(160),
                                          height: ScreenUtil.getInstance()
                                              .setWidth(160),
                                          fit: BoxFit.fill,
                                        ),
                                  Expanded(
                                    flex: 1,
                                    child: Container(
                                      padding: EdgeInsets.fromLTRB(10, 0, 5, 0),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: <Widget>[
                                          Text(
                                            item == null ? "" : item.title,
                                            maxLines: 2,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                                fontSize:
                                                    ScreenUtil.getInstance()
                                                        .setSp(
                                                            NORMAL_FONT_SIZE +
                                                                3),
                                                color: black),
                                          ),
                                          // Padding(
                                          //   padding: EdgeInsets.fromLTRB(
                                          //       0, 5, 5, 5),
                                          //   child: Html(
                                          //     data: item == null
                                          //         ? ""
                                          //         : item.datas[index].sku_str,
                                          //     // style: TextStyle(
                                          //     //     fontSize: ScreenUtil
                                          //     //             .getInstance()
                                          //     //         .setSp(
                                          //     //             SMALL_FONT_SIZE),
                                          //     //     color: black_99),
                                          //   ),
                                          // ),
                                          Padding(
                                            padding:
                                                EdgeInsets.fromLTRB(0, 0, 5, 4),
                                            child: Text(
                                              item == null ? "" : "X" + "1",
                                              style: TextStyle(
                                                  fontSize:
                                                      ScreenUtil.getInstance()
                                                          .setSp(
                                                              SMALL_FONT_SIZE),
                                                  color: black_99),
                                            ),
                                          ),
                                          Text(
                                            item == null
                                                ? ""
                                                : '¥' +
                                                    item.allprice.toString(),
                                            style: TextStyle(
                                                fontSize:
                                                    ScreenUtil.getInstance()
                                                        .setSp(BIG_FONT_SIZE),
                                                color: mainColor),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            )
                          : Container(
                              padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
                              child: ListView.builder(
                                  shrinkWrap: true,
                                  itemBuilder:
                                      (BuildContext context, int index) {
                                    return Container(
                                      padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
                                      child: new Row(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: <Widget>[
                                          item == null ||
                                                  item.datas[index].img == ""
                                              ? Image.asset(
                                                  'images/app_icon.png',
                                                  width:
                                                      ScreenUtil.getInstance()
                                                          .setWidth(160),
                                                  height:
                                                      ScreenUtil.getInstance()
                                                          .setWidth(160),
                                                  fit: BoxFit.fill,
                                                )
                                              : CachedNetworkImage(
                                                  imageUrl: Api.ImgBaseUrl +
                                                      item.datas[index].img,
                                                  width:
                                                      ScreenUtil.getInstance()
                                                          .setWidth(160),
                                                  height:
                                                      ScreenUtil.getInstance()
                                                          .setWidth(160),
                                                  fit: BoxFit.fill,
                                                ),
                                          Expanded(
                                            flex: 1,
                                            child: Container(
                                              padding: EdgeInsets.fromLTRB(
                                                  10, 0, 5, 0),
                                              child: Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: <Widget>[
                                                  Text(
                                                    item == null
                                                        ? ""
                                                        : item.datas[index]
                                                            .goods_name,
                                                    maxLines: 2,
                                                    overflow:
                                                        TextOverflow.ellipsis,
                                                    style: TextStyle(
                                                        fontSize: ScreenUtil
                                                                .getInstance()
                                                            .setSp(
                                                                NORMAL_FONT_SIZE -
                                                                    3),
                                                        color: black),
                                                  ),
                                                  Padding(
                                                    padding:
                                                        EdgeInsets.fromLTRB(
                                                            0, 5, 5, 5),
                                                    child: Html(
                                                      data: item == null
                                                          ? ""
                                                          : item.datas[index]
                                                              .sku_str,
                                                      // style: TextStyle(
                                                      //     fontSize: ScreenUtil
                                                      //             .getInstance()
                                                      //         .setSp(
                                                      //             SMALL_FONT_SIZE),
                                                      //     color: black_99),
                                                    ),
                                                  ),
                                                  Padding(
                                                    padding:
                                                        EdgeInsets.fromLTRB(
                                                            0, 0, 5, 4),
                                                    child: Text(
                                                      item == null
                                                          ? ""
                                                          : "X" +
                                                              item.datas[index]
                                                                  .num
                                                                  .toString(),
                                                      style: TextStyle(
                                                          fontSize: ScreenUtil
                                                                  .getInstance()
                                                              .setSp(
                                                                  SMALL_FONT_SIZE),
                                                          color: black_99),
                                                    ),
                                                  ),
                                                  Text(
                                                    item == null
                                                        ? ""
                                                        : '¥' +
                                                            item.datas[index]
                                                                .allprice
                                                                .toString(),
                                                    style: TextStyle(
                                                        fontSize: ScreenUtil
                                                                .getInstance()
                                                            .setSp(
                                                                BIG_FONT_SIZE),
                                                        color: mainColor),
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    );
                                  },
                                  itemCount:
                                      item == null ? 0 : item.datas.length),
                            ),
                      Container(height: 10, color: divideColor),
                      Padding(
                        padding: EdgeInsets.fromLTRB(15, 20, 15, 8),
                        child: GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            ClipboardData data =
                                new ClipboardData(text: item.order_num);
                            Clipboard.setData(data);
                            Fluttertoast.showToast(
                                msg: "复制成功", gravity: ToastGravity.CENTER);
                          },
                          child: Row(
                            children: <Widget>[
                              Text(
                                item == null ? "" : '订单编号: ' + item.order_num,
                                style: TextStyle(
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE - 2),
                                    color: black_99),
                              ),
                              Container(
                                width: 3,
                              ),
                              Icon(
                                Icons.content_copy,
                                size: 16,
                                color: Colors.grey,
                              )
                            ],
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(15, 0, 15, 8),
                        child: Text(
                          item == null
                              ? ""
                              : '下单时间: ' + item.create_time.toString(),
                          style: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE - 2),
                              color: black_99),
                        ),
                      ),
                      Offstage(
                        offstage: item == null || int.parse(item.status) < 2,
                        child: Padding(
                          padding: EdgeInsets.fromLTRB(15, 0, 15, 8),
                          child: Text(
                            item == null
                                ? ""
                                : '付款时间: ' +
                                    item.pay_time
                                        .toString()
                                        .replaceAll("null", ""),
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE - 2),
                                color: black_99),
                          ),
                        ),
                      ),
                      Offstage(
                        offstage: item == null || int.parse(item.status) < 3,
                        child: Padding(
                          padding: EdgeInsets.fromLTRB(15, 0, 15, 8),
                          child: Text(
                            item == null
                                ? ""
                                : '发货时间: ' +
                                    item.deliver_time
                                        .toString()
                                        .replaceAll("null", ""),
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE - 2),
                                color: black_99),
                          ),
                        ),
                      ),
                      Offstage(
                        offstage: item == null || int.parse(item.status) < 4,
                        child: Padding(
                          padding: EdgeInsets.fromLTRB(15, 0, 15, 8),
                          child: Text(
                            item == null
                                ? ""
                                : '收货时间: ' +
                                    item.deliver_time
                                        .toString()
                                        .replaceAll("null", ""),
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE - 2),
                                color: black_99),
                          ),
                        ),
                      ),
                      Container(
                        height: 10,
                        color: divideColor,
                        margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
                      ),
                      widget.type == "2"
                          ? Center()
                          : Padding(
                              padding: EdgeInsets.fromLTRB(15, 8, 15, 20),
                              child: Row(
                                children: <Widget>[
                                  Expanded(
                                    child: Text('运费',
                                        style: TextStyle(
                                            color: black,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(NORMAL_FONT_SIZE - 2))),
                                  ),
                                  Text(
                                    item == null ? "0" : item.postage,
                                    style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(BIG_FONT_SIZE),
                                        color: black_99),
                                  ),
                                ],
                              ),
                            ),
                      widget.type == "2"
                          ? Center()
                          : Padding(
                              padding: EdgeInsets.fromLTRB(15, 0, 15, 20),
                              child: Row(
                                children: <Widget>[
                                  Expanded(
                                    child: Text('优惠',
                                        style: TextStyle(
                                            color: black,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(NORMAL_FONT_SIZE - 2))),
                                  ),
                                  Text(
                                    item == null ? "0" : item.coupons,
                                    style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(BIG_FONT_SIZE),
                                        color: black_99),
                                  ),
                                ],
                              ),
                            ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 8, 15, 10),
                        child: Row(
                          children: <Widget>[
                            Expanded(
                              child: Text('',
                                  style: TextStyle(color: black, fontSize: 14)),
                            ),
                            Text('实际付款：',
                                style:
                                    TextStyle(color: black_99, fontSize: 13)),
                            Text(
                              item == null
                                  ? ""
                                  : '¥' +
                                      formatNum(double.parse(item.allprice) -
                                              double.parse(item.coupons) +
                                              double.parse(
                                                  item.postage == "null"
                                                      ? '0'
                                                      : item.postage),2),
                              style: TextStyle(
                                  fontSize: ScreenUtil.getInstance().setSp(35),
                                  color: mainColor),
                            ),
                          ],
                        ),
                      ),
                      new Container(
                        margin: EdgeInsets.fromLTRB(0, 8, 15, 0),
                        child: new Row(
                          children: <Widget>[
                            item == null || item.status == "1"
                                ? Center()
                                : Container(
                                    // width: double.infinity,
                                    padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
                                    alignment: Alignment.centerRight,
                                    child: GestureDetector(
                                      child: Container(
                                          padding:
                                              EdgeInsets.fromLTRB(10, 2, 10, 2),
                                          decoration: BoxDecoration(
                                              color: mainColor,
                                              borderRadius:
                                                  BorderRadius.circular(20)),
                                          child: Text("订单回执",
                                              style: TextStyle(
                                                  color: white,
                                                  fontSize:
                                                      ScreenUtil.getInstance()
                                                          .setSp(26)))),
                                      onTap: () {
                                        Navigator.of(context).push(
                                            new MaterialPageRoute(
                                                builder: (context) {
                                          return new OrderHuiZhiPage(
                                              order: item);
                                        }));
                                      },
                                      behavior: HitTestBehavior.opaque,
                                    ),
                                  ),
                            Expanded(
                              child: Text(''),
                            ),
                            widget.type == "2"
                                ? Offstage(
                                    offstage: item == null
                                        ? true
                                        : (item.logistics
                                                    .replaceAll("null", "") ==
                                                "" ||
                                            item.express_number
                                                    .replaceAll("null", "") ==
                                                ""),
                                    child: new GestureDetector(
                                      onTap: () {
                                        Navigator.of(context).push(
                                            new MaterialPageRoute(
                                                builder: (context) {
                                          return new MyHomePage(
                                            title: item.status == '11'
                                                ? item.logistics_exchange_goods
                                                : item.logistics,
                                            express_number: item.status == '11'
                                                ? item
                                                    .exchange_goods_express_number
                                                : item.express_number,
                                            phone: item.contact_number,
                                          );
                                        }));
                                      },
                                      child: new Container(
                                        padding:
                                            EdgeInsets.fromLTRB(10, 2, 10, 2),
                                        margin:
                                            EdgeInsets.fromLTRB(10, 10, 10, 0),
                                        decoration: new BoxDecoration(
                                            borderRadius:
                                                BorderRadius.circular(10.0),
                                            border: Border.all(
                                                color: mainColor, width: 1.0)),
                                        child: Text(
                                          '查看物流',
                                          style: TextStyle(
                                              fontSize: ScreenUtil.getInstance()
                                                  .setSp(26),
                                              color: mainColor),
                                        ),
                                      ),
                                    ),
                                  )
                                : Offstage(
                                    offstage: item == null
                                        ? true
                                        : item.status != "3",
                                    child: new GestureDetector(
                                      onTap: () {
                                        Navigator.of(context).push(
                                            new MaterialPageRoute(
                                                builder: (context) {
                                          return new MyHomePage(
                                            title: item.status == '11'
                                                ? item.logistics_exchange_goods
                                                : item.logistics,
                                            express_number: item.status == '11'
                                                ? item
                                                    .exchange_goods_express_number
                                                : item.express_number,
                                            phone: item.contact_number,
                                          );
                                        }));
                                      },
                                      child: new Container(
                                        padding:
                                            EdgeInsets.fromLTRB(10, 2, 10, 2),
                                        margin:
                                            EdgeInsets.fromLTRB(10, 10, 10, 0),
                                        decoration: new BoxDecoration(
                                            borderRadius:
                                                BorderRadius.circular(10.0),
                                            border: Border.all(
                                                color: mainColor, width: 1.0)),
                                        child: Text(
                                          '查看物流',
                                          style: TextStyle(
                                              fontSize: ScreenUtil.getInstance()
                                                  .setSp(26),
                                              color: mainColor),
                                        ),
                                      ),
                                    ),
                                  ),
                            widget.type == '1'
                                ? Center()
                                : Offstage(
                                    offstage: item == null
                                        ? true
                                        : item.status != "1",
                                    child: new GestureDetector(
                                      onTap: () {
                                        final ThemeData theme =
                                            Theme.of(context);
                                        final TextStyle dialogTextStyle =
                                            theme.textTheme.subhead.copyWith(
                                                color: theme
                                                    .textTheme.caption.color);
                                        showDialog(
                                            context: context,
                                            child: CupertinoAlertDialog(
                                              title: Text('取消提示'),
                                              content: Text('取消后不可撤回，确定取消该订单吗？',
                                                  style: dialogTextStyle),
                                              actions: <Widget>[
                                                CupertinoDialogAction(
                                                  child: const Text(
                                                    '再想想',
                                                    style: TextStyle(
                                                        color: Colors.grey),
                                                  ),
                                                  onPressed: () {
                                                    Navigator.pop(
                                                        context, false);
                                                  },
                                                ),
                                                CupertinoDialogAction(
                                                  child: const Text(
                                                    '确定取消',
                                                    style: TextStyle(
                                                        color: mainColor),
                                                  ),
                                                  onPressed: () async {
                                                    Navigator.pop(
                                                        context, true);
                                                    showDialog(
                                                        context: context,
                                                        barrierDismissible:
                                                            false,
                                                        builder: (_) {
                                                          return new NetLoadingDialog(
                                                            loadingText:
                                                                "取消中...",
                                                            bgColor:
                                                                Color.fromARGB(
                                                                    255,
                                                                    0,
                                                                    0,
                                                                    0),
                                                            requestCallBack:
                                                                null,
                                                            outsideDismiss:
                                                                false,
                                                          );
                                                        });
                                                    calcleOrder();
                                                  },
                                                ),
                                              ],
                                            ));
                                      },
                                      child: new Container(
                                        padding:
                                            EdgeInsets.fromLTRB(10, 2, 10, 2),
                                        margin:
                                            EdgeInsets.fromLTRB(0, 10, 0, 0),
                                        decoration: new BoxDecoration(
                                            borderRadius:
                                                BorderRadius.circular(10.0),
                                            border: Border.all(
                                                color: Colors.black54,
                                                width: 1.0)),
                                        child: Text(
                                          '取消订单',
                                          style: TextStyle(
                                              fontSize: ScreenUtil.getInstance()
                                                  .setSp(26),
                                              color: Colors.black54),
                                        ),
                                      ),
                                    ),
                                  ),
                            item == null ||
                                    widget.type == '1' ||
                                    item.status == "3"
                                ? Center()
                                : Offstage(
                                    child: new GestureDetector(
                                      onTap: () {
                                        if (item.status == "1") {
                                          Navigator.of(context).push<int>(
                                              MaterialPageRoute(
                                                  builder: (context) {
                                            return new OrderPayPage(
                                                orderId: item.id,
                                                goods_id:
                                                    item.datas[0].goods_id,
                                                create_time: item.create_time,
                                                orderNum: item.order_num,
                                                totalMoney: formatNum(
                                                    (double.parse(
                                                            item.allprice) +
                                                        double.parse(
                                                            item.postage)),
                                                    2));
                                          })).then((int result) {
                                            print("payresult===>$result");
                                          });
                                        } else if (item.status == "3") {
                                          final ThemeData theme =
                                              Theme.of(context);
                                          final TextStyle dialogTextStyle =
                                              theme.textTheme.subhead.copyWith(
                                                  color: theme
                                                      .textTheme.caption.color);
                                          showDialog(
                                              context: context,
                                              child: CupertinoAlertDialog(
                                                title: Text('确认提示'),
                                                content: Text('确定您已收到订单商品吗',
                                                    style: dialogTextStyle),
                                                actions: <Widget>[
                                                  CupertinoDialogAction(
                                                    child: const Text(
                                                      '取消',
                                                      style: TextStyle(
                                                          color: Colors.grey),
                                                    ),
                                                    onPressed: () {
                                                      Navigator.pop(
                                                          context, false);
                                                    },
                                                  ),
                                                  CupertinoDialogAction(
                                                    child: const Text(
                                                      '确定收货',
                                                      style: TextStyle(
                                                          color: mainColor),
                                                    ),
                                                    onPressed: () async {
                                                      Navigator.pop(
                                                          context, true);
                                                      showDialog(
                                                          context: context,
                                                          barrierDismissible:
                                                              false,
                                                          builder: (_) {
                                                            return new NetLoadingDialog(
                                                              loadingText:
                                                                  "确认中...",
                                                              bgColor: Color
                                                                  .fromARGB(255,
                                                                      0, 0, 0),
                                                              requestCallBack:
                                                                  null,
                                                              outsideDismiss:
                                                                  false,
                                                            );
                                                          });
                                                      confirmOrder();
                                                    },
                                                  ),
                                                ],
                                              ));
                                        }
                                      },
                                      child: new Container(
                                        padding:
                                            EdgeInsets.fromLTRB(10, 7, 10, 7),
                                        margin: EdgeInsets.only(left: 10),
                                        decoration: new BoxDecoration(
                                            color: mainColor,
                                            borderRadius:
                                                BorderRadius.circular(10.0),
                                            border: Border.all(
                                                color: white, width: 1.0)),
                                        child: Text(
                                          item == null
                                              ? ""
                                              : item.status_zh + "",
                                          style: TextStyle(
                                              fontSize: ScreenUtil.getInstance()
                                                  .setSp(26),
                                              color: white),
                                        ),
                                      ),
                                    ),
                                    offstage: item == null
                                        ? true
                                        : (item.status != "1" ||
                                            item.status != "3"))
                          ],
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        ));
  }

  confirmOrder() async {
    Map map = new Map();
    map['order_id'] = widget.order_id;
    map['token'] = token;
    map['sign_type'] = SignType.CONFIRM_ORDER;
    Response<String> response =
        await HttpUtil().post(Api.CONFIRM_ORDER, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    Navigator.of(context).pop(1);
    Fluttertoast.showToast(msg: userMap['msg']);
    if (code == 1 && mounted) {
      getOrderDetail();
    }
  }

  calcleOrder() async {
    Map map = new Map();
    map['order_id'] = widget.order_id;
    map['token'] = token;
    map['sign_type'] = SignType.CANCLE_ORDER;
    Response<String> response =
        await HttpUtil().post(Api.CANCLE_ORDER, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    Navigator.of(context).pop(1);
    Fluttertoast.showToast(msg: userMap['msg']);
    if (code == 1) {
      Navigator.of(context).pop();
    }
  }

  String formatNum(double num, int postion) {
    if ((num.toString().length - num.toString().lastIndexOf(".") - 1) <
        postion) {
      return num.toStringAsFixed(postion)
          .substring(0, num.toString().lastIndexOf(".") + postion + 1)
          .toString();
    } else {
      return num.toString()
          .substring(0, num.toString().lastIndexOf(".") + postion + 1)
          .toString();
    }
  }
}
